
Imports System.Data.SqlClient
Partial Class Secure_Default_CMS
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim userbol As Boolean
        Dim objUserIdentity As Web.Security.FormsIdentity
        Dim objTicket As Web.Security.FormsAuthenticationTicket

        If User.Identity.IsAuthenticated Then
            objUserIdentity = User.Identity
            objTicket = objUserIdentity.Ticket


            Dim con As SqlConnection
            Dim cmd As SqlCommand
            Dim rdr As SqlDataReader

            con = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("sqlConn"))
            cmd = New SqlCommand("SELECT UserRole, LastLoginDate FROM JJV_USERS WHERE UserName = '" & objTicket.Name & "';", con)
            con.Open()
            rdr = cmd.ExecuteReader()
            While rdr.Read
                If rdr("UserRole") = 1 Then
                    userbol = True
                ElseIf rdr("UserRole") = 2 Then
                    userbol = True
                ElseIf rdr("UserRole") = 3 Then
                    userbol = False
                End If
                Label1.Text = "Your last login date and time is: " & rdr("LastLoginDate")
            End While

            rdr.Close()
            con.Close()

            Session("userid") = objTicket.UserData
        Else
            If Session("isadmin") <> 0 Then
                Response.Redirect("Access_Error.aspx")
            End If
        End If
        Cont()
    End Sub
    Protected Sub Cont()
        If Not IsPostBack Then
            Dim con As SqlConnection
            Dim cmd As SqlCommand
            Dim rdr As SqlDataReader

            Dim urlVar As String = Nothing
            Dim titleVar As String = Nothing
            Dim pageidVar As Integer = Nothing
            Dim pageSubtitleVar As String = Nothing
            Dim pageDescriptionVar As String = Nothing

            con = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("sqlConn"))
            cmd = New SqlCommand("select * from pages where CMSPage = 1", con)
            con.Open()
            rdr = cmd.ExecuteReader()
            While rdr.Read
                If rdr("url") = "index.aspx" Then
                    pageidVar = rdr(ID)
                End If
                pageNavigationLabel.Text &= "<li><a href=" & rdr("url") & ">" & rdr("title") & "</a></li>"
            End While
            rdr.Close()
            con.Close()
        End If
    End Sub
End Class
